//
//  BinningCarVC.m
//  ChangJiuGroup
//
//  Created by Hank on 2017/11/17.
//  Copyright © 2017年 周昊. All rights reserved.
//
// Header的高度
#define HeaderHeight 36
// 第一个section判断
#define OneSection(section) section == 1
// 第二个section判断
#define TwoSection(section) section == 2
// 列车方向类型默认为西向
#define DepartDirectionType [self.trainShiftModel.departDirectionType isEqualToString:@"1"]
// 西向行数
#define WestRows 3
// 东向行数
#define EastRows 4

#import "BinningCarVC.h"
#import "BinningHeadView.h"
#import "BinningMerchandiseCarCell.h"
#import "BinningContainerCell.h"
#import "BinningWestShowCell.h"
#import "BinningEastShowCell.h"
#import "ScanVC.h"
#import "StyleDIY.h"

@interface BinningCarVC ()<UITextFieldDelegate>
// 头部数据
@property (strong, nonatomic) NSArray *headDataArray;
// 数字图片数据
@property (strong, nonatomic) NSArray *numberImageArray;
// 集装箱数据
@property (strong, nonatomic) NSArray *containerDataArray;
// 商品车Label数组
@property (strong, nonatomic) NSMutableArray *merchandiseLabelArray;
// 集装箱Label数组
@property (strong, nonatomic) NSMutableArray *containerLabelArray;
// GPSLabel数组
@property (strong, nonatomic) NSMutableArray *GPSLabelArray;
// 核对示意图Label数组
@property (strong, nonatomic) NSMutableArray *schematicDiagramLabelArray;

@end

@implementation BinningCarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航栏
    [self setNavC];
    // 加载头部视图
    [self loadTableHeadView];
    // 加载数据
    [self loadData];
    // 注册Cell
    [self registerCells];
    // 恢复数据
    [self recoveryData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
// 加载数据
- (void)loadData
{
    self.headDataArray = @[@{@"binning_merchandiseCar":@"商品车"},@{@"binning_container":@"集装箱"},@{@"binning_schematicDiagram":@"核对示意图"}];
    self.numberImageArray = @[@"binning_one",@"binning_two",@"binning_three",@"binning_three"];
    // 判断车辆是方向
    NSString *twoContainerDataKey = DepartDirectionType ? DefaultSteelNo : DefaultStentsNO;
    NSString *twoContainerDataValue = DepartDirectionType ? DefaultTray:DefaultStents;
    self.containerDataArray = @[@{DefaultStentsNO:DefaultStents},@{twoContainerDataKey:twoContainerDataValue}];
}

// 注册Cell
- (void)registerCells
{
    UINib *nib = [UINib nibWithNibName:[BinningMerchandiseCarCell reuseIdentifier] bundle:nil];
    [_myTableView registerNib:nib forCellReuseIdentifier:[BinningMerchandiseCarCell reuseIdentifier]];
    nib = [UINib nibWithNibName:[BinningContainerCell reuseIdentifier] bundle:nil];
    [_myTableView registerNib:nib forCellReuseIdentifier:[BinningContainerCell reuseIdentifier]];
    nib = [UINib nibWithNibName:[BinningWestShowCell reuseIdentifier] bundle:nil];
    [_myTableView registerNib:nib forCellReuseIdentifier:[BinningWestShowCell reuseIdentifier]];
    nib = [UINib nibWithNibName:[BinningEastShowCell reuseIdentifier] bundle:nil];
    [_myTableView registerNib:nib forCellReuseIdentifier:[BinningEastShowCell reuseIdentifier]];
}
#pragma mark - initArray
// 初始化数组
- (NSMutableArray *)merchandiseLabelArray
{
    if (!_merchandiseLabelArray) {
        _merchandiseLabelArray = [[NSMutableArray alloc]init];
    }
    return _merchandiseLabelArray;
}

- (NSMutableArray *)containerLabelArray
{
    if (!_containerLabelArray) {
        _containerLabelArray = [[NSMutableArray alloc]init];
    }
    return _containerLabelArray;
}

- (NSMutableArray *)GPSLabelArray
{
    if (!_GPSLabelArray) {
        _GPSLabelArray = [[NSMutableArray alloc]init];
    }
    return _GPSLabelArray;
}

- (NSMutableArray *)schematicDiagramLabelArray
{
    if (!_schematicDiagramLabelArray) {
        _schematicDiagramLabelArray = [[NSMutableArray alloc]init];
    }
    return _schematicDiagramLabelArray;
}


#pragma mark - 导航栏
- (void)setNavC
{
    self.title = @"装箱";
}

#pragma mark - pushVinCameraVC
// 跳转Vin条形码扫码页面
- (void)pushVinCameraVC:(NSIndexPath *)indexPath type:(NSString *)type
{
    ScanVC *scanVC = [[ScanVC alloc]init];
    scanVC.style = [StyleDIY notSquare];
    scanVC.isOpenInterestRect = YES;
    scanVC.libraryType = SLT_Native;
    scanVC.scanCodeType = SCT_BarCode128;
    scanVC.indexPath = indexPath;
    // 防止循环引用
    WEAK_REF(self);
    // 扫码结果返回更新 Block
    [scanVC setScanBlock:^(NSString *scanContentStr, NSIndexPath *indexPath) {
        if (indexPath.section == 0) {
            //同步更新商品车(商品车VIN码)
            BinningMerchandiseCarCell *binningMerchandiseCarCell = [weak_self.myTableView cellForRowAtIndexPath:indexPath];
            binningMerchandiseCarCell.barCodeLabel.text = scanContentStr;
        }else if (indexPath.section == 1) {
            //同步更新集装箱(车辆支架编号,钢铁托盘编号)
            BinningContainerCell *binningContainerCell = [weak_self.myTableView cellForRowAtIndexPath:indexPath];
            // 判断扫码类型
            if ([type isEqualToString:@"1"]) {
                binningContainerCell.barCodeLabel.text = scanContentStr;
            }else if([type isEqualToString:@"2"]){
                binningContainerCell.GPSCode.text = scanContentStr;
            }
            // 同步更新核对示意图(车辆支架编号,钢铁托盘编号)
            [weak_self syncUpdateSchematicDiagram:indexPath type:type scanContentStr:scanContentStr];
        }
    }];
    
    [self.navigationController pushViewController:scanVC animated:YES];
}
// 同步更新核对示意图(车辆支架编号,钢铁托盘编号)
- (void)syncUpdateSchematicDiagram:(NSIndexPath *)indexPath type:(NSString *)type scanContentStr:(NSString *)scanContentStr
{
    NSIndexPath *binningSchematicDiagramCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:2];
    if ([self.trainShiftModel.departDirectionType isEqualToString:@"1"]) {
        BinningWestShowCell *binningWestShowCell = [self.myTableView cellForRowAtIndexPath:binningSchematicDiagramCellIndexPath];
        if ([type isEqualToString:@"1"]) {
            if (indexPath.row == 0) {
                binningWestShowCell.stentsNumber.text = scanContentStr;
            }else if (indexPath.row == 1){
                binningWestShowCell.trayNumber.text = scanContentStr;
            }
        }
    }else{
        BinningEastShowCell *binningEastShowCell = [self.myTableView cellForRowAtIndexPath:binningSchematicDiagramCellIndexPath];
        if ([type isEqualToString:@"1"]) {
            if (indexPath.row == 0) {
                binningEastShowCell.stentsOneNumber.text = scanContentStr;
            }else if (indexPath.row == 1){
                binningEastShowCell.stentsTwoNumber.text = scanContentStr;
            }
        }
    }
}

#pragma mark - recoveryData
// 恢复数据
-(void)recoveryData
{
    if (_binningWestModel != nil) {
        // 恢复集装箱编号
        _containerTF.text = _binningWestModel.containerNo;
        // 恢复商品车数据
        for (int i = 0; i < WestRows; i++) {
            // 恢复商品车数据
            [self recoveryMerchandiseCarData:[_binningWestModel.carVIN componentsSeparatedByString:@","][i] index:i];
        }
        // 恢复支架托盘编号数据
        for (int i = 0; i < 2; i++) {
            // 恢复支架托盘编号数据
            [self recoveryContainerData:_binningWestModel.stentsNo stentsTwoNo:nil trayNo:_binningWestModel.trayNo index:i strNullable:NO];
        }
        // 恢复GPS数据
        for (int i = 0; i < 2; i++) {
            // 修改GPS数据
            [self recoveryGPSData:i == 0 ? _binningWestModel.stentsGPSNo :_binningWestModel.trayGPSNo index:i];
        }
        // 恢复示意图
        [self recoverySchematicDiagram:_binningWestModel binningEastModel:nil];
    }else if (_binningEastModel != nil) {
        // 恢复集装箱编号
        _containerTF.text = _binningEastModel.containerNo;
        // 恢复商品车数据
        for (int i = 0; i < EastRows; i++) {
            // 恢复商品车数据
            [self recoveryMerchandiseCarData:[_binningEastModel.carVIN componentsSeparatedByString:@","][i] index:i];
        }
        // 恢复支架托盘编号数据
        for (int i = 0; i < 2; i++) {
            // 恢复支架托盘编号数据
            [self recoveryContainerData:_binningEastModel.leftStentsNo stentsTwoNo:_binningEastModel.rightStentsNo trayNo:nil index:i strNullable:NO];
        }
        // 恢复GPS数据
        for (int i = 0; i < 2; i++) {
            // 修改GPS数据
            [self recoveryGPSData:i == 0 ? _binningEastModel.leftStentsGPSNo :_binningEastModel.rightStentsGPSNo index:i];
        }
        // 恢复示意图
        [self recoverySchematicDiagram:nil binningEastModel:_binningEastModel];
    }
}
// 恢复商品车数据
- (void)recoveryMerchandiseCarData:(NSString *)carVIN index:(NSInteger)index
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    BinningMerchandiseCarCell *binningMerchandiseCarCell = [self.myTableView cellForRowAtIndexPath:indexPath];
    binningMerchandiseCarCell.barCodeLabel.text = carVIN;
}
// 恢复支架托盘编号数据
- (void)recoveryContainerData:(NSString *)stentsOneNo stentsTwoNo:(NSString *)stentsTwoNo trayNo:(NSString *)trayNo index:(NSInteger)index strNullable:(BOOL)strNullable
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:1];
    BinningContainerCell *binningContainerCell = [self.myTableView cellForRowAtIndexPath:indexPath];
    if (index == 0) {
        if (JudgeStrNotEqualNull(stentsOneNo)) {
            binningContainerCell.barCodeLabel.text = stentsOneNo;
        }else if (strNullable == YES) {
            binningContainerCell.barCodeLabel.text = stentsOneNo;
        }
    }
    if (index == 1) {
        if (JudgeStrNotEqualNull(stentsTwoNo)) {
            binningContainerCell.barCodeLabel.text = stentsTwoNo;
        }else if (strNullable == YES) {
            binningContainerCell.barCodeLabel.text = stentsTwoNo;
        }
    }else if (index == 1) {
        if (JudgeStrNotEqualNull(trayNo)) {
            binningContainerCell.barCodeLabel.text = trayNo;
        }else if (strNullable == YES) {
            binningContainerCell.barCodeLabel.text = trayNo;
        }
    }
}
// 恢复GPS数据
- (void)recoveryGPSData:(NSString *)GPS index:(NSInteger)index
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:1];
    BinningContainerCell *binningContainerCell = [self.myTableView cellForRowAtIndexPath:indexPath];
    binningContainerCell.GPSCode.text = GPS;
}
// 恢复示意图
- (void)recoverySchematicDiagram:(BinningWestModel *)binningWestModel binningEastModel:(BinningEastModel *)binningEastModel
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
    
    // 恢复选择顺序数据
    if (binningWestModel != nil) {
        NSArray *sequenceDataArray = [binningWestModel.putSequence componentsSeparatedByString:@","];
        BinningWestShowCell *binningWestShowCell = [self.myTableView cellForRowAtIndexPath:indexPath];
        if ([sequenceDataArray[0] isEqualToString:sequenceDataArray[1]] && [sequenceDataArray[0] isEqualToString:sequenceDataArray[2]]) {
            // 没有选择顺序
        }else if ([sequenceDataArray[1] isEqualToString:sequenceDataArray[2]]) {
            // 只选择一个顺序
            [binningWestShowCell selectStateBtn:binningWestShowCell.topStentsBtnArray[[sequenceDataArray[0] integerValue] - 1] type:0];
        }else{
            // 全部选择顺序
            [binningWestShowCell selectStateBtn:binningWestShowCell.topStentsBtnArray[[sequenceDataArray[0] integerValue] - 1] type:0];
            [binningWestShowCell selectStateBtn:binningWestShowCell.bottomStentsBtnArray[[sequenceDataArray[1] integerValue] - 1] type:1];
        }
        // 恢复支架托盘编号数据
        binningWestShowCell.stentsNumber.text = binningWestModel.stentsNo;
        binningWestShowCell.trayNumber.text = binningWestModel.trayNo;
    }else{
        NSArray *sequenceDataArray = [binningEastModel.putSequence componentsSeparatedByString:@","];
        BinningEastShowCell *binningEastShowCell = [self.myTableView cellForRowAtIndexPath:indexPath];
        if ([sequenceDataArray[0] isEqualToString:sequenceDataArray[1]] && [sequenceDataArray[0] isEqualToString:sequenceDataArray[2]] && [sequenceDataArray[0] isEqualToString:sequenceDataArray[3]]) {
            // 没有选择顺序
        }else if ([sequenceDataArray[1] isEqualToString:sequenceDataArray[2]] && [sequenceDataArray[1] isEqualToString:sequenceDataArray[3]]) {
            // 选择一个顺序
            [binningEastShowCell selectStateBtn:binningEastShowCell.topStentsBtnOneArray[[sequenceDataArray[0] integerValue] - 1] type:0];
        }else if ([sequenceDataArray[2] isEqualToString:sequenceDataArray[3]]) {
            // 选择两个顺序
            [binningEastShowCell selectStateBtn:binningEastShowCell.topStentsBtnOneArray[[sequenceDataArray[0] integerValue] - 1] type:0];
            [binningEastShowCell selectStateBtn:binningEastShowCell.bottomStentsBtnOneArray[[sequenceDataArray[1] integerValue] - 1] type:1];
        }else{
            // 全部选择顺序
            [binningEastShowCell selectStateBtn:binningEastShowCell.topStentsBtnOneArray[[sequenceDataArray[0] integerValue] - 1] type:0];
            [binningEastShowCell selectStateBtn:binningEastShowCell.bottomStentsBtnOneArray[[sequenceDataArray[1] integerValue] - 1] type:1];
            [binningEastShowCell selectStateBtn:binningEastShowCell.topStentsBtnTwoArray[[sequenceDataArray[2] integerValue] - 1] type:2];
        }
        // 恢复支架托盘编号数据
        binningEastShowCell.stentsOneNumber.text = binningEastModel.leftStentsNo;
        binningEastShowCell.stentsTwoNumber.text = binningEastModel.rightStentsNo;
    }
}

#pragma mark - changeAlertView
// 修改弹框视图
- (void)changeAlertView:(NSIndexPath *)indexPath type:(NSString *)type
{
    NSString *textFieldMessage;
    // 根据点击来判断数据
    if (indexPath.section == 0) {
        UILabel *merchandise = self.merchandiseLabelArray[indexPath.row];
        textFieldMessage = merchandise.text;
    }else{
        if ([type isEqualToString:@"1"]) {
            UILabel *container = self.containerLabelArray[indexPath.row];
            textFieldMessage = container.text;
        }else if ([type isEqualToString:@"2"]) {
            UILabel *GPSLabel = self.GPSLabelArray[indexPath.row];
            textFieldMessage = GPSLabel.text;
        }
    }
    
    if (![textFieldMessage isEqualToString:DefaultCommercial] && ![textFieldMessage isEqualToString:DefaultStents] && ![textFieldMessage isEqualToString:DefaultTray] && ![textFieldMessage isEqualToString:DefaultGPS]) {
        // 弹出修改弹框视图
        UIAlertView *editAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"可根据需求进行修改" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        
        editAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
        // 修改的编码
        [[editAlert textFieldAtIndex:0] setText:textFieldMessage];
        
        // 防止循环引用
        WEAK_REF(self);
        
        editAlert.tapBlock = ^(UIAlertView *alertView, NSInteger buttonIndex) {
            if (buttonIndex == alertView.firstOtherButtonIndex) {
                NSString *contentStr = [[alertView textFieldAtIndex:0] text];
                // 根据点击来判断数据
                if (indexPath.section == 0) {
                    // 修改商品车数据
                    [weak_self recoveryMerchandiseCarData:contentStr index:indexPath.row];
                }else{
                    if ([type isEqualToString:@"1"]) {
                        // 修改支架托盘编号数据
                        [weak_self recoveryContainerData:indexPath.row == 0 ? contentStr : nil stentsTwoNo:DepartDirectionType ? nil : indexPath.row == 1 ? contentStr : nil trayNo:DepartDirectionType ?indexPath.row == 1 ? contentStr : nil : nil index:indexPath.row strNullable:YES];
                        // 修改核对示意图(车辆支架编号,钢铁托盘编号)
                        [weak_self syncUpdateSchematicDiagram:indexPath type:type scanContentStr:contentStr];
                    }else if ([type isEqualToString:@"2"]) {
                        // 修改GPS数据
                        [weak_self recoveryGPSData:contentStr index:indexPath.row];
                    }
                }
            } else if (buttonIndex == alertView.cancelButtonIndex) {
                NSLog(@"Cancelled.");
            }
        };
        //开始编辑才会显示确定
//        av.shouldEnableFirstOtherButtonBlock = ^BOOL(UIAlertView *alertView){
//            return ([[[alertView textFieldAtIndex:1] text] length] > 0);
//        };
        
        [editAlert show];
    }
}

#pragma mark - tableView headView
// 设置tableView headView
- (void)loadTableHeadView
{
    _myTableView.tableHeaderView = self.tableHeadView;
}

#pragma mark - TableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return TwoSection(section) ? 1 : section == 0 ? DepartDirectionType ? WestRows : EastRows : 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 防止循环引用
    WEAK_REF(self);
    
    if (indexPath.section == 0) {
        // 商品车
        BinningMerchandiseCarCell *cell = [tableView dequeueReusableCellWithIdentifier:[BinningMerchandiseCarCell reuseIdentifier] forIndexPath:indexPath];
        cell.indexPath = indexPath;
        // 商品车扫码 Block
        [cell setMerchandiseCarClickBlock:^(NSIndexPath *indexPath){
            [weak_self pushVinCameraVC:indexPath type:@""];
        }];
        // 修改商品车编码 Block
        [cell setChangeCodeBlock:^(NSIndexPath *indexPath){
            if (indexPath.section < 2) {
                // 修改弹框视图
                [weak_self changeAlertView:indexPath type:nil];
            }
        }];
        [self.merchandiseLabelArray addObject:cell.barCodeLabel];
        [cell setData:self.numberImageArray[indexPath.row]];
        return cell;
    }else if (indexPath.section == 1) {
        // 集装箱(车辆支架编号,钢铁托盘编号)
        BinningContainerCell *cell = [tableView dequeueReusableCellWithIdentifier:[BinningContainerCell reuseIdentifier] forIndexPath:indexPath];
        cell.indexPath = indexPath;
        // 车辆支架扫码或者钢铁托盘扫码 Block
        [cell setContainerClickBlock:^(NSIndexPath *indexPath, NSString *type){
            [weak_self pushVinCameraVC:indexPath type:type];
        }];
        [cell setChangeCodeBlock:^(NSIndexPath *indexPath, NSString *type){
            if (indexPath.section < 2) {
                // 修改弹框视图
                [weak_self changeAlertView:indexPath type:type];
            }
        }];
        [self.containerLabelArray addObject:cell.barCodeLabel];
        [self.GPSLabelArray addObject:cell.GPSCode];
        [cell setData:self.containerDataArray[indexPath.row]];
        return cell;
    }else{
        // 核对示意图
        // 判断列车方向
        if (DepartDirectionType) {
            // 支架 + 托盘
            BinningWestShowCell *cell = [tableView dequeueReusableCellWithIdentifier:[BinningWestShowCell reuseIdentifier] forIndexPath:indexPath];
            cell.myTableView = tableView;
            cell.trainShiftModel = self.trainShiftModel;
            cell.merchandiseLabelArray = self.merchandiseLabelArray;
            cell.containerLabelArray = self.containerLabelArray;
            cell.GPSLabelArray = self.GPSLabelArray;
            cell.containerDataArray = self.containerDataArray;
            cell.schematicDiagramLabelArray = self.schematicDiagramLabelArray;
            cell.containerTF = self.containerTF;
            // 更新数据使用
            cell.binningWestModel = self.binningWestModel;
            // 保存核对示意图内容
            [self.schematicDiagramLabelArray addObject:cell.stentsNumber];
            [self.schematicDiagramLabelArray addObject:cell.trayNumber];
            return cell;
        }else{
            // 支架 + 支架
            BinningEastShowCell *cell = [tableView dequeueReusableCellWithIdentifier:[BinningEastShowCell reuseIdentifier] forIndexPath:indexPath];
            cell.myTableView = tableView;
            cell.trainShiftModel = self.trainShiftModel;
            cell.merchandiseLabelArray = self.merchandiseLabelArray;
            cell.containerLabelArray = self.containerLabelArray;
            cell.GPSLabelArray = self.GPSLabelArray;
            cell.containerDataArray = self.containerDataArray;
            cell.schematicDiagramLabelArray = self.schematicDiagramLabelArray;
            cell.containerTF = self.containerTF;
            // 更新数据使用
            cell.binningEastModel = self.binningEastModel;
            // 保存核对示意图内容
            [self.schematicDiagramLabelArray addObject:cell.stentsOneNumber];
            [self.schematicDiagramLabelArray addObject:cell.stentsTwoNumber];
            return cell;
        }
    }
}
#pragma mark - TableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return TwoSection(indexPath.section) ? 304 : OneSection(indexPath.section) ? 88 : 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return HeaderHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return TwoSection(section) ? 0.1 : 10;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    BinningHeadView *binningHeadView = [[BinningHeadView alloc]init];
    binningHeadView = BundleXib(@"BinningHeadView");
    binningHeadView.frame = CGRectMake(0, 0, kScreenWidth, HeaderHeight);
    binningHeadView.headImage.image = [UIImage imageNamed:[[self.headDataArray[section] allKeys] objectAtIndex:0]];
    binningHeadView.headContent.text = [[self.headDataArray[section] allValues] objectAtIndex:0];
    if (TwoSection(section)) {
        binningHeadView.backgroundColor = [UIColor clearColor];
    }
    return binningHeadView;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc]init];
    footerView.frame = CGRectMake(0, 0, kScreenWidth, 10);
    footerView.backgroundColor = [UIColor lightGrayColor];
    return footerView;
}

- (void)dealloc
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
